package com.javaweb.admin.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javaweb.admin.entity.NcTaskLog;
import com.javaweb.admin.entity.Scheduled;
import com.javaweb.admin.mapper.KdlTransReportMapper;
import com.javaweb.admin.mapper.ScheduledMapper;
import com.javaweb.admin.query.QffFeedbackQuery;
import com.javaweb.admin.query.RGRQuery;
import com.javaweb.admin.service.AbstractJob;
import com.javaweb.admin.service.INcTaskLogService;
import com.javaweb.common.config.CommonConfig;
import com.javaweb.common.utils.DateUtils;
import com.seegw.shaphar.IKDLService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SyncTransReportJob extends AbstractJob {
    private static final Logger log = LoggerFactory.getLogger(SyncTransReportJob.class);
    @Autowired
    ScheduledMapper scheduledMapper;

    @Autowired
    IKDLService kdlService;

    @Autowired
    private KdlTransReportMapper kdlTransReportMapper;
    @Autowired
    INcTaskLogService iNcTaskLogService;
    @Override
    public String getName() {
        QueryWrapper<Scheduled> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("classpath",this.getClass().getName());
        Scheduled entity = scheduledMapper.selectOne(queryWrapper);
        return entity.getName();
    }

    @Override
    public void execute() {
        QffFeedbackQuery query = new QffFeedbackQuery();
        log.info("开始同步运输报表...");
        NcTaskLog taskLog = new NcTaskLog();
        taskLog.setTaskType("同步运输报表");
        taskLog.setBillCount(0);
        taskLog.setStartTime(DateUtils.now());
        String billno = "";

        query.setPrincipalid(CommonConfig.kdlCompanyId);
        query.setStarttime(kdlService.getTransReportMaxSyncTime());
        query.setEndtime(DateUtils.dateTime());
        kdlService.syncTransReport(query);
        log.info("运输报表同步完成...");
        taskLog.setBillNo(billno);
        taskLog.setEndTime(DateUtils.now());
        iNcTaskLogService.save(taskLog);


        //QffFeedbackQuery query = new QffFeedbackQuery();
        log.info("开始同步养护报表...");
        //NcTaskLog taskLog = new NcTaskLog();
        taskLog.setTaskType("同步养护报表");
        taskLog.setBillCount(0);
        taskLog.setStartTime(DateUtils.now());
        //String billno = "";

        query.setPrincipalid(CommonConfig.kdlCompanyId);
        query.setStarttime(kdlService.getMaintainReportMaxSyncTime());
        query.setEndtime(DateUtils.dateTime());
        kdlService.syncMaintainReport(query);
        log.info("养护报表同步完成...");
        taskLog.setBillNo(billno);
        taskLog.setEndTime(DateUtils.now());
        iNcTaskLogService.save(taskLog);

    }
}
